package com.example.shengyin.frontController;

import com.alibaba.fastjson2.JSON;
import com.example.shengyin.entity.Article;
import com.example.shengyin.entity.ArticleSimple;
import com.example.shengyin.entity.Page;
import com.example.shengyin.service.ArticleService;
import com.example.shengyin.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * AdminController
 * 
 * @author ruoyi
 * @date 2023-07-29
 */
@RestController
@RequestMapping("/front/redio")
@Validated
@CrossOrigin(origins = "*", maxAge = 3600,allowCredentials="true")
//swagger
@Api(tags = "FrontVideoController", description = "视频中心")
public class FrontVideoController
{
    @Autowired
    private ArticleService service;
    @Autowired
    private RedisTemplate redisTemplate;
    public Map ReMap(){
        Map<String,Object> map=new HashMap<>();
        map.put("公司简介 ComProfile",new ArrayList<>(Arrays.asList("CompanyInfo")));
        map.put("媒体报道 Media",new ArrayList<>(Arrays.asList("媒体报道 Media")));
        map.put("交流合作 Cooperate",new ArrayList<>(Arrays.asList("交流合作")));
        map.put("大事记 Event",new ArrayList<>(Arrays.asList("大事记")));
        map.put("公司新闻 Comnews",new ArrayList<>(Arrays.asList("开业活动 Opening","国际交流 International","员工活动   \n" +
                "Staff","亲子活动  \n" +
                "Parent-child","公益讲座 Public","公益活动 Interest","家长培训Training","社会关注 Social ","全部 null")));
        map.put("活动讲座 Lecture",new ArrayList<>(Arrays.asList("热门推荐","专题精选","门店信息")));
        map.put("言语科普 Speech",new ArrayList<>(Arrays.asList("言语科普")));
        map.put("视频中心","企业活动 Corporate  品牌宣传 Brand  家庭训练技巧 Family  朗朗 Lang");
        return map;
    }
    @ApiOperation("详细内容")
    @GetMapping(value = "/finddetail/{id}")
    public Result select(@PathVariable(value = "id") Long id)
    {
        Article article = service.selectById(id);
        System.out.println(JSON.toJSONString(article));
        if(article==null)
            return Result.error("没有找到数据");
        return Result.success(article);
    }

    @ApiOperation("视频中心->分页查找")
    @GetMapping(value = "/findMediaCideos")
    public Result findMediaCideos(@ApiParam(name = "page",value = "页数") @RequestParam(required = true) int page,
                                  @ApiParam(name = "limit",value = "条数") @RequestParam(required = true) int limit)
    {
        Page page1=new Page(page,limit);
        int comnews = service.countTotall("视频中心", null, null, null, null);
        List<ArticleSimple> articles = service.articleList2(page1, "视频中心", null, null, null, null);
        if(comnews==0||articles==null)
            return Result.success(page,"没有数据");
        page1.setCount(comnews);
        page1.setPageTotal(comnews);
        page1.setData(articles);
        return Result.success(page1);
    }

    @ApiOperation("视频中心->企业活动")
    @GetMapping(value = "/findComActis")
    public Result findComActis(@ApiParam(name = "page",value = "页数") @RequestParam(required = true) int page,
                               @ApiParam(name = "limit",value = "条数") @RequestParam(required = true) int limit)
    {

        Page page1=new Page(page,limit);
        int comnews = service.countTotall("视频中心", "Corporate", null, null, null);
        List<ArticleSimple> articles = service.articleList2(page1, "视频中心", "Corporate", null, null, null);
        if(comnews==0||articles==null)
            return Result.success(page,"没有数据");
        page1.setCount(comnews);
        page1.setPageTotal(comnews);
        page1.setData(articles);
        return Result.success(page1);
    }
    @ApiOperation("视频中心->品牌宣传")
    @GetMapping(value = "/findXuanchuans")
    public Result findXuanchuans(@ApiParam(name = "page",value = "页数") @RequestParam(required = true) int page,
                                 @ApiParam(name = "limit",value = "条数") @RequestParam(required = true) int limit)
    {
        Page page1=new Page(page,limit);
        int comnews = service.countTotall("视频中心", "Brand", null, null, null);
        List<ArticleSimple> articles = service.articleList2(page1, "视频中心", "Brand", null, null, null);
        if(comnews==0||articles==null)
            return Result.success(page,"没有数据");
        page1.setCount(comnews);
        page1.setPageTotal(comnews);
        page1.setData(articles);
        return Result.success(page1);
    }
    @ApiOperation("视频中心->家庭训练技巧")
    @GetMapping(value = "/findXunlian")
    public Result findXunlian(@ApiParam(name = "page",value = "页数") @RequestParam(required = true) int page,
                              @ApiParam(name = "limit",value = "条数") @RequestParam(required = true) int limit)
    {
        Page page1=new Page(page,limit);
        int comnews = service.countTotall("视频中心", "Family", null, null, null);
        List<ArticleSimple> articles = service.articleList2(page1, "视频中心", "Family", null, null, null);
        if(comnews==0||articles==null)
            return Result.success(page,"没有数据");
        page1.setCount(comnews);
        page1.setPageTotal(comnews);
        page1.setData(articles);
        return Result.success(page1);
    }
    @ApiOperation("视频中心->朗朗")
    @GetMapping(value = "/findLang")
    public Result findLang(@ApiParam(name = "page",value = "页数") @RequestParam(required = true) int page,
                           @ApiParam(name = "limit",value = "条数") @RequestParam(required = true) int limit)
    {
        Page page1=new Page(page,limit);
        int comnews = service.countTotall("视频中心", "Lang", null, null, null);
        List<ArticleSimple> articles = service.articleList2(page1, "视频中心", "Lang", null, null, null);
        if(comnews==0||articles==null)
            return Result.success(page,"没有数据");
        page1.setCount(comnews);
        page1.setPageTotal(comnews);
        page1.setData(articles);
        return Result.success(page1);
    }
}
